﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using LibKetoan;
using System.Reflection;
using System.Runtime.InteropServices;
using Excel;

namespace Ketoan
{
	/// <summary>
	/// Summary description for frmDm.
	/// </summary>
	public class frmDmng : System.Windows.Forms.Form
	{
		private System.Windows.Forms.DataGrid dataGrid1;
		private System.Windows.Forms.Button butKetthuc;
		private AccessData a;
		private System.Data.DataTable dt=new System.Data.DataTable();
		private System.Windows.Forms.Button butMoi;
		private System.Windows.Forms.Button butSua;
		private System.Windows.Forms.Button butLuu;
		private System.Windows.Forms.Button butBoqua;
		private System.Windows.Forms.Button butHuy;
		private long l_id;
		private int i_userid;
		private string s_mmyy,sql;
		private System.Windows.Forms.TextBox ma;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox tim;
		Excel.Application oxl;
		Excel._Workbook owb;
		Excel._Worksheet osheet;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.TextBox ten;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.NumericUpDown stt;
		private System.Windows.Forms.Label label11;
		private System.Windows.Forms.Label label13;
		private System.Windows.Forms.CheckBox hide;
		private System.Windows.Forms.TextBox thuocct;
		private System.Windows.Forms.TextBox mact;
		private MaskedBox.MaskedBox ngaybd;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.TextBox matieuct;
		private MaskedBox.MaskedBox ngaykt;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label7;
		private MaskedTextBox.MaskedTextBox tongkpdd;
		private MaskedTextBox.MaskedTextBox kpnamnay;
		private System.Windows.Forms.Label label8;
		private MaskedTextBox.MaskedTextBox sokptnlk;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.Label label10;
		private System.Windows.Forms.TextBox coquanth;
		private System.Windows.Forms.Label label12;
		private System.Windows.Forms.Label label14;
		private System.Windows.Forms.TextBox mang;
		private System.Windows.Forms.TextBox mn_syt;
		private System.Windows.Forms.Button butExcel;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmDmng(AccessData acc,string mmyy,int userid)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			a=acc;s_mmyy=mmyy;i_userid=userid;
			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmDmng));
			this.dataGrid1 = new System.Windows.Forms.DataGrid();
			this.butKetthuc = new System.Windows.Forms.Button();
			this.butMoi = new System.Windows.Forms.Button();
			this.butSua = new System.Windows.Forms.Button();
			this.butLuu = new System.Windows.Forms.Button();
			this.butBoqua = new System.Windows.Forms.Button();
			this.butHuy = new System.Windows.Forms.Button();
			this.ma = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.tim = new System.Windows.Forms.TextBox();
			this.hide = new System.Windows.Forms.CheckBox();
			this.label6 = new System.Windows.Forms.Label();
			this.ten = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.thuocct = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.mact = new System.Windows.Forms.TextBox();
			this.stt = new System.Windows.Forms.NumericUpDown();
			this.label11 = new System.Windows.Forms.Label();
			this.label13 = new System.Windows.Forms.Label();
			this.ngaybd = new MaskedBox.MaskedBox();
			this.label5 = new System.Windows.Forms.Label();
			this.matieuct = new System.Windows.Forms.TextBox();
			this.ngaykt = new MaskedBox.MaskedBox();
			this.label4 = new System.Windows.Forms.Label();
			this.label7 = new System.Windows.Forms.Label();
			this.tongkpdd = new MaskedTextBox.MaskedTextBox();
			this.kpnamnay = new MaskedTextBox.MaskedTextBox();
			this.label8 = new System.Windows.Forms.Label();
			this.sokptnlk = new MaskedTextBox.MaskedTextBox();
			this.label9 = new System.Windows.Forms.Label();
			this.label10 = new System.Windows.Forms.Label();
			this.coquanth = new System.Windows.Forms.TextBox();
			this.label12 = new System.Windows.Forms.Label();
			this.mang = new System.Windows.Forms.TextBox();
			this.mn_syt = new System.Windows.Forms.TextBox();
			this.label14 = new System.Windows.Forms.Label();
			this.butExcel = new System.Windows.Forms.Button();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.stt)).BeginInit();
			this.SuspendLayout();
			// 
			// dataGrid1
			// 
			this.dataGrid1.AlternatingBackColor = System.Drawing.Color.Lavender;
			this.dataGrid1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.dataGrid1.BackColor = System.Drawing.Color.WhiteSmoke;
			this.dataGrid1.BackgroundColor = System.Drawing.SystemColors.Control;
			this.dataGrid1.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.dataGrid1.CaptionBackColor = System.Drawing.SystemColors.Control;
			this.dataGrid1.CaptionFont = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.dataGrid1.CaptionForeColor = System.Drawing.Color.MidnightBlue;
			this.dataGrid1.DataMember = "";
			this.dataGrid1.FlatMode = true;
			this.dataGrid1.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.dataGrid1.ForeColor = System.Drawing.Color.MidnightBlue;
			this.dataGrid1.GridLineColor = System.Drawing.Color.Gainsboro;
			this.dataGrid1.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None;
			this.dataGrid1.HeaderFont = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
			this.dataGrid1.HeaderForeColor = System.Drawing.Color.WhiteSmoke;
			this.dataGrid1.LinkColor = System.Drawing.Color.Teal;
			this.dataGrid1.Location = new System.Drawing.Point(8, 8);
			this.dataGrid1.Name = "dataGrid1";
			this.dataGrid1.ParentRowsBackColor = System.Drawing.Color.Gainsboro;
			this.dataGrid1.ParentRowsForeColor = System.Drawing.Color.MidnightBlue;
			this.dataGrid1.ReadOnly = true;
			this.dataGrid1.RowHeaderWidth = 10;
			this.dataGrid1.SelectionBackColor = System.Drawing.Color.CadetBlue;
			this.dataGrid1.SelectionForeColor = System.Drawing.Color.WhiteSmoke;
			this.dataGrid1.Size = new System.Drawing.Size(776, 368);
			this.dataGrid1.TabIndex = 28;
			this.dataGrid1.CurrentCellChanged += new System.EventHandler(this.dataGrid1_CurrentCellChanged);
			// 
			// butKetthuc
			// 
			this.butKetthuc.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.butKetthuc.Image = ((System.Drawing.Bitmap)(resources.GetObject("butKetthuc.Image")));
			this.butKetthuc.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butKetthuc.Location = new System.Drawing.Point(547, 504);
			this.butKetthuc.Name = "butKetthuc";
			this.butKetthuc.Size = new System.Drawing.Size(70, 25);
			this.butKetthuc.TabIndex = 21;
			this.butKetthuc.Text = "&Kết thúc";
			this.butKetthuc.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.butKetthuc.Click += new System.EventHandler(this.butKetthuc_Click);
			// 
			// butMoi
			// 
			this.butMoi.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.butMoi.Image = ((System.Drawing.Bitmap)(resources.GetObject("butMoi.Image")));
			this.butMoi.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butMoi.Location = new System.Drawing.Point(175, 504);
			this.butMoi.Name = "butMoi";
			this.butMoi.Size = new System.Drawing.Size(60, 25);
			this.butMoi.TabIndex = 17;
			this.butMoi.Text = "     &Mới";
			this.butMoi.Click += new System.EventHandler(this.butMoi_Click);
			// 
			// butSua
			// 
			this.butSua.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.butSua.Image = ((System.Drawing.Bitmap)(resources.GetObject("butSua.Image")));
			this.butSua.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butSua.Location = new System.Drawing.Point(237, 504);
			this.butSua.Name = "butSua";
			this.butSua.Size = new System.Drawing.Size(60, 25);
			this.butSua.TabIndex = 18;
			this.butSua.Text = "    &Sửa";
			this.butSua.Click += new System.EventHandler(this.butSua_Click);
			// 
			// butLuu
			// 
			this.butLuu.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.butLuu.Enabled = false;
			this.butLuu.Image = ((System.Drawing.Bitmap)(resources.GetObject("butLuu.Image")));
			this.butLuu.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butLuu.Location = new System.Drawing.Point(299, 504);
			this.butLuu.Name = "butLuu";
			this.butLuu.Size = new System.Drawing.Size(60, 25);
			this.butLuu.TabIndex = 15;
			this.butLuu.Text = "     &Lưu";
			this.butLuu.Click += new System.EventHandler(this.butLuu_Click);
			// 
			// butBoqua
			// 
			this.butBoqua.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.butBoqua.Enabled = false;
			this.butBoqua.Image = ((System.Drawing.Bitmap)(resources.GetObject("butBoqua.Image")));
			this.butBoqua.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butBoqua.Location = new System.Drawing.Point(361, 504);
			this.butBoqua.Name = "butBoqua";
			this.butBoqua.Size = new System.Drawing.Size(60, 25);
			this.butBoqua.TabIndex = 16;
			this.butBoqua.Text = "&Bỏ qua";
			this.butBoqua.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.butBoqua.Click += new System.EventHandler(this.butBoqua_Click);
			// 
			// butHuy
			// 
			this.butHuy.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.butHuy.Image = ((System.Drawing.Bitmap)(resources.GetObject("butHuy.Image")));
			this.butHuy.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butHuy.Location = new System.Drawing.Point(485, 504);
			this.butHuy.Name = "butHuy";
			this.butHuy.Size = new System.Drawing.Size(60, 25);
			this.butHuy.TabIndex = 20;
			this.butHuy.Text = "    &Hủy";
			this.butHuy.Click += new System.EventHandler(this.butHuy_Click);
			// 
			// ma
			// 
			this.ma.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.ma.BackColor = System.Drawing.SystemColors.HighlightText;
			this.ma.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
			this.ma.Enabled = false;
			this.ma.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.ma.Location = new System.Drawing.Point(232, 380);
			this.ma.MaxLength = 20;
			this.ma.Name = "ma";
			this.ma.Size = new System.Drawing.Size(56, 21);
			this.ma.TabIndex = 1;
			this.ma.Text = "";
			this.ma.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
			this.ma.Validated += new System.EventHandler(this.ma_Validated);
			// 
			// label1
			// 
			this.label1.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.label1.Location = new System.Drawing.Point(288, 380);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(104, 23);
			this.label1.TabIndex = 0;
			this.label1.Text = "Tên dự án :";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// tim
			// 
			this.tim.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.tim.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.tim.Location = new System.Drawing.Point(8, 5);
			this.tim.Name = "tim";
			this.tim.Size = new System.Drawing.Size(776, 21);
			this.tim.TabIndex = 29;
			this.tim.Text = "Tìm kiếm";
			this.tim.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			this.tim.TextChanged += new System.EventHandler(this.tim_TextChanged);
			this.tim.Enter += new System.EventHandler(this.tim_Enter);
			// 
			// hide
			// 
			this.hide.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.hide.Enabled = false;
			this.hide.Location = new System.Drawing.Point(648, 482);
			this.hide.Name = "hide";
			this.hide.Size = new System.Drawing.Size(128, 16);
			this.hide.TabIndex = 14;
			this.hide.Text = "Không sử dụng nữa";
			this.hide.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
			// 
			// label6
			// 
			this.label6.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.label6.Location = new System.Drawing.Point(136, 380);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(96, 23);
			this.label6.TabIndex = 30;
			this.label6.Text = "Mã dự án :";
			this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// ten
			// 
			this.ten.Anchor = ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.ten.BackColor = System.Drawing.SystemColors.HighlightText;
			this.ten.Enabled = false;
			this.ten.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.ten.Location = new System.Drawing.Point(392, 380);
			this.ten.Name = "ten";
			this.ten.Size = new System.Drawing.Size(392, 21);
			this.ten.TabIndex = 2;
			this.ten.Text = "";
			this.ten.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
			this.ten.Validated += new System.EventHandler(this.ten_Validated);
			// 
			// label2
			// 
			this.label2.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.label2.Location = new System.Drawing.Point(280, 403);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(112, 23);
			this.label2.TabIndex = 35;
			this.label2.Text = "Thuộc chương trình :";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// thuocct
			// 
			this.thuocct.Anchor = ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.thuocct.BackColor = System.Drawing.SystemColors.HighlightText;
			this.thuocct.Enabled = false;
			this.thuocct.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.thuocct.Location = new System.Drawing.Point(392, 403);
			this.thuocct.Name = "thuocct";
			this.thuocct.Size = new System.Drawing.Size(392, 21);
			this.thuocct.TabIndex = 5;
			this.thuocct.Text = "";
			this.thuocct.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
			// 
			// label3
			// 
			this.label3.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.label3.Location = new System.Drawing.Point(-8, 403);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(112, 23);
			this.label3.TabIndex = 37;
			this.label3.Text = "Mã số chương trình :";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// mact
			// 
			this.mact.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.mact.BackColor = System.Drawing.SystemColors.HighlightText;
			this.mact.Enabled = false;
			this.mact.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.mact.Location = new System.Drawing.Point(104, 403);
			this.mact.MaxLength = 20;
			this.mact.Name = "mact";
			this.mact.Size = new System.Drawing.Size(64, 21);
			this.mact.TabIndex = 3;
			this.mact.Text = "";
			this.mact.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
			// 
			// stt
			// 
			this.stt.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.stt.BackColor = System.Drawing.SystemColors.HighlightText;
			this.stt.Enabled = false;
			this.stt.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.stt.Location = new System.Drawing.Point(104, 380);
			this.stt.Maximum = new System.Decimal(new int[] {
																9999999,
																0,
																0,
																0});
			this.stt.Name = "stt";
			this.stt.Size = new System.Drawing.Size(64, 21);
			this.stt.TabIndex = 0;
			this.stt.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
			// 
			// label11
			// 
			this.label11.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.label11.Location = new System.Drawing.Point(56, 380);
			this.label11.Name = "label11";
			this.label11.Size = new System.Drawing.Size(48, 23);
			this.label11.TabIndex = 49;
			this.label11.Text = "Số TT :";
			this.label11.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label13
			// 
			this.label13.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.label13.Location = new System.Drawing.Point(24, 426);
			this.label13.Name = "label13";
			this.label13.Size = new System.Drawing.Size(80, 23);
			this.label13.TabIndex = 52;
			this.label13.Text = "Ngày bắt đầu :";
			this.label13.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// ngaybd
			// 
			this.ngaybd.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.ngaybd.BackColor = System.Drawing.SystemColors.HighlightText;
			this.ngaybd.Enabled = false;
			this.ngaybd.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.ngaybd.Location = new System.Drawing.Point(104, 426);
			this.ngaybd.Mask = "##/##/####";
			this.ngaybd.MaxLength = 10;
			this.ngaybd.Name = "ngaybd";
			this.ngaybd.Size = new System.Drawing.Size(64, 21);
			this.ngaybd.TabIndex = 6;
			this.ngaybd.Text = "";
			this.ngaybd.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
			this.ngaybd.Validated += new System.EventHandler(this.ngaybd_Validated);
			// 
			// label5
			// 
			this.label5.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.label5.Location = new System.Drawing.Point(152, 403);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(80, 23);
			this.label5.TabIndex = 57;
			this.label5.Text = "Mã số tiểu :";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// matieuct
			// 
			this.matieuct.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.matieuct.BackColor = System.Drawing.SystemColors.HighlightText;
			this.matieuct.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
			this.matieuct.Enabled = false;
			this.matieuct.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.matieuct.Location = new System.Drawing.Point(232, 403);
			this.matieuct.MaxLength = 20;
			this.matieuct.Name = "matieuct";
			this.matieuct.Size = new System.Drawing.Size(56, 21);
			this.matieuct.TabIndex = 4;
			this.matieuct.Text = "";
			this.matieuct.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
			// 
			// ngaykt
			// 
			this.ngaykt.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.ngaykt.BackColor = System.Drawing.SystemColors.HighlightText;
			this.ngaykt.Enabled = false;
			this.ngaykt.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.ngaykt.Location = new System.Drawing.Point(232, 426);
			this.ngaykt.Mask = "##/##/####";
			this.ngaykt.MaxLength = 10;
			this.ngaykt.Name = "ngaykt";
			this.ngaykt.Size = new System.Drawing.Size(64, 21);
			this.ngaykt.TabIndex = 7;
			this.ngaykt.Text = "";
			this.ngaykt.Validated += new System.EventHandler(this.ngaykt_Validated);
			// 
			// label4
			// 
			this.label4.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.label4.Location = new System.Drawing.Point(152, 426);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(80, 23);
			this.label4.TabIndex = 60;
			this.label4.Text = "Ngày KT :";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label7
			// 
			this.label7.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.label7.Location = new System.Drawing.Point(312, 426);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(80, 23);
			this.label7.TabIndex = 61;
			this.label7.Text = "Tổng kinh phí :";
			this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// tongkpdd
			// 
			this.tongkpdd.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.tongkpdd.BackColor = System.Drawing.SystemColors.HighlightText;
			this.tongkpdd.Enabled = false;
			this.tongkpdd.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.tongkpdd.Location = new System.Drawing.Point(392, 426);
			this.tongkpdd.Masked = MaskedTextBox.MaskedTextBox.Mask.None;
			this.tongkpdd.Name = "tongkpdd";
			this.tongkpdd.Size = new System.Drawing.Size(160, 21);
			this.tongkpdd.TabIndex = 8;
			this.tongkpdd.Text = "";
			this.tongkpdd.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			this.tongkpdd.Validated += new System.EventHandler(this.tongkpdd_Validated);
			// 
			// kpnamnay
			// 
			this.kpnamnay.Anchor = ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.kpnamnay.BackColor = System.Drawing.SystemColors.HighlightText;
			this.kpnamnay.Enabled = false;
			this.kpnamnay.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.kpnamnay.Location = new System.Drawing.Point(648, 426);
			this.kpnamnay.Masked = MaskedTextBox.MaskedTextBox.Mask.None;
			this.kpnamnay.Name = "kpnamnay";
			this.kpnamnay.Size = new System.Drawing.Size(136, 21);
			this.kpnamnay.TabIndex = 9;
			this.kpnamnay.Text = "";
			this.kpnamnay.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			this.kpnamnay.Validated += new System.EventHandler(this.kpnamnay_Validated);
			// 
			// label8
			// 
			this.label8.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.label8.Location = new System.Drawing.Point(544, 426);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(104, 23);
			this.label8.TabIndex = 76;
			this.label8.Text = "Kinh phí năm nay :";
			this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// sokptnlk
			// 
			this.sokptnlk.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.sokptnlk.BackColor = System.Drawing.SystemColors.HighlightText;
			this.sokptnlk.Enabled = false;
			this.sokptnlk.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.sokptnlk.Location = new System.Drawing.Point(104, 450);
			this.sokptnlk.Masked = MaskedTextBox.MaskedTextBox.Mask.None;
			this.sokptnlk.Name = "sokptnlk";
			this.sokptnlk.Size = new System.Drawing.Size(192, 21);
			this.sokptnlk.TabIndex = 10;
			this.sokptnlk.Text = "";
			this.sokptnlk.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			this.sokptnlk.Validated += new System.EventHandler(this.sokptnlk_Validated);
			// 
			// label9
			// 
			this.label9.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.label9.Location = new System.Drawing.Point(-32, 450);
			this.label9.Name = "label9";
			this.label9.Size = new System.Drawing.Size(136, 23);
			this.label9.TabIndex = 78;
			this.label9.Text = "L.kế từ khi khởi đầu :";
			this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label10
			// 
			this.label10.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.label10.Location = new System.Drawing.Point(280, 450);
			this.label10.Name = "label10";
			this.label10.Size = new System.Drawing.Size(112, 23);
			this.label10.TabIndex = 80;
			this.label10.Text = "Cơ quan thực hiện :";
			this.label10.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// coquanth
			// 
			this.coquanth.Anchor = ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.coquanth.BackColor = System.Drawing.SystemColors.HighlightText;
			this.coquanth.Enabled = false;
			this.coquanth.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.coquanth.Location = new System.Drawing.Point(392, 450);
			this.coquanth.Name = "coquanth";
			this.coquanth.Size = new System.Drawing.Size(392, 21);
			this.coquanth.TabIndex = 11;
			this.coquanth.Text = "";
			this.coquanth.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
			// 
			// label12
			// 
			this.label12.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.label12.Location = new System.Drawing.Point(-48, 474);
			this.label12.Name = "label12";
			this.label12.Size = new System.Drawing.Size(152, 23);
			this.label12.TabIndex = 82;
			this.label12.Text = "Mã khai báo nguồn :";
			this.label12.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// mang
			// 
			this.mang.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.mang.BackColor = System.Drawing.SystemColors.HighlightText;
			this.mang.Enabled = false;
			this.mang.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.mang.Location = new System.Drawing.Point(104, 474);
			this.mang.MaxLength = 20;
			this.mang.Name = "mang";
			this.mang.Size = new System.Drawing.Size(192, 21);
			this.mang.TabIndex = 12;
			this.mang.Text = "";
			this.mang.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
			// 
			// mn_syt
			// 
			this.mn_syt.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.mn_syt.BackColor = System.Drawing.SystemColors.HighlightText;
			this.mn_syt.Enabled = false;
			this.mn_syt.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.mn_syt.Location = new System.Drawing.Point(392, 474);
			this.mn_syt.MaxLength = 20;
			this.mn_syt.Name = "mn_syt";
			this.mn_syt.Size = new System.Drawing.Size(160, 21);
			this.mn_syt.TabIndex = 13;
			this.mn_syt.Text = "";
			this.mn_syt.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
			// 
			// label14
			// 
			this.label14.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.label14.Location = new System.Drawing.Point(328, 474);
			this.label14.Name = "label14";
			this.label14.Size = new System.Drawing.Size(64, 23);
			this.label14.TabIndex = 84;
			this.label14.Text = "Mã SYT :";
			this.label14.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// butExcel
			// 
			this.butExcel.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.butExcel.Image = ((System.Drawing.Bitmap)(resources.GetObject("butExcel.Image")));
			this.butExcel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butExcel.Location = new System.Drawing.Point(424, 504);
			this.butExcel.Name = "butExcel";
			this.butExcel.Size = new System.Drawing.Size(60, 25);
			this.butExcel.TabIndex = 88;
			this.butExcel.Text = "      &In";
			this.butExcel.Click += new System.EventHandler(this.butExcel_Click);
			// 
			// frmDmng
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(792, 573);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.butExcel,
																		  this.mn_syt,
																		  this.label14,
																		  this.mang,
																		  this.sokptnlk,
																		  this.label12,
																		  this.coquanth,
																		  this.mact,
																		  this.label10,
																		  this.label9,
																		  this.tongkpdd,
																		  this.kpnamnay,
																		  this.label8,
																		  this.label7,
																		  this.ngaybd,
																		  this.label4,
																		  this.ngaykt,
																		  this.matieuct,
																		  this.label5,
																		  this.label13,
																		  this.label11,
																		  this.stt,
																		  this.label3,
																		  this.thuocct,
																		  this.label2,
																		  this.ten,
																		  this.label6,
																		  this.hide,
																		  this.tim,
																		  this.ma,
																		  this.label1,
																		  this.butHuy,
																		  this.butBoqua,
																		  this.butLuu,
																		  this.butSua,
																		  this.butMoi,
																		  this.butKetthuc,
																		  this.dataGrid1});
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "frmDmng";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Danh mục dự án";
			this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
			this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.frmDmng_KeyDown);
			this.Load += new System.EventHandler(this.frmDmng_Load);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.stt)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void frmDmng_Load(object sender, System.EventArgs e)
		{
			load_grid();
			AddGridTableStyle();
			ref_text();
		}		

		private void load_grid()
		{
			sql="select a.*,to_char(a.ngaybd,'dd/mm/yyyy') as bd,to_char(a.ngaykt,'dd/mm/yyyy') as kt ";
			sql+=" from a_dmng a ";
			sql+=" where a.loaikp=0 order by a.stt";
			dt=a.get_data(sql).Tables[0];
			dataGrid1.DataSource=dt;
		}

		private void AddGridTableStyle()
		{
			DataGridTableStyle ts =new DataGridTableStyle();
			ts.MappingName = dt.TableName;
			ts.AlternatingBackColor = Color.Beige;
			ts.BackColor = Color.GhostWhite;
			ts.ForeColor = Color.MidnightBlue;
			ts.GridLineColor = Color.RoyalBlue;
			ts.HeaderBackColor = Color.MidnightBlue;
			ts.HeaderForeColor = Color.Lavender;
			ts.SelectionBackColor = Color.Teal;
			ts.SelectionForeColor = Color.PaleGreen;
			ts.ReadOnly=false;
			ts.RowHeaderWidth=10;
						
			DataGridTextBoxColumn TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "id";
			TextCol.HeaderText = "";
			TextCol.Width = 0;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "stt";
			TextCol.HeaderText = "STT";
			TextCol.Width = 30;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "mada";
			TextCol.HeaderText = "Mã dự án";
			TextCol.Width = 40;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "ten";
			TextCol.HeaderText = "Tên dự án";
			TextCol.Width = 250;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "thuocct";
			TextCol.HeaderText = "Thuộc chương trình";
			TextCol.Width = 250;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "bd";
			TextCol.HeaderText = "Ngày BĐ";
			TextCol.Width = 65;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "kt";
			TextCol.HeaderText = "Ngày KT";
			TextCol.Width = 65;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "tongkpdd";
			TextCol.HeaderText = "Tổng kinh phí";
			TextCol.Width = 100;
			TextCol.Format="###,###,###,###,###";
			TextCol.Alignment=HorizontalAlignment.Right;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "kpnamnay";
			TextCol.HeaderText = "KP năm nay";
			TextCol.Width = 100;
			TextCol.Format="###,###,###,###,###";
			TextCol.Alignment=HorizontalAlignment.Right;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "sokptnlk";
			TextCol.HeaderText = "Lũy kế";
			TextCol.Width = 100;
			TextCol.Format="###,###,###,###,###";
			TextCol.Alignment=HorizontalAlignment.Right;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "coquanth";
			TextCol.HeaderText = "Cơ quan thực hiện";
			TextCol.Width = 250;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);
		}

		private void butKetthuc_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void ena_object(bool ena)
		{
			dataGrid1.Enabled=!ena;
			ma.Enabled=ten.Enabled=ena;
			tim.Enabled=!ena;
			stt.Enabled=hide.Enabled=ena;
			mact.Enabled=matieuct.Enabled=thuocct.Enabled=ngaybd.Enabled=ngaykt.Enabled=ena;
			tongkpdd.Enabled=kpnamnay.Enabled=sokptnlk.Enabled=coquanth.Enabled=mang.Enabled=mn_syt.Enabled=ena;
			butMoi.Enabled=!ena;
			butSua.Enabled=!ena;
			butLuu.Enabled=ena;
			butBoqua.Enabled=ena;
			butExcel.Enabled=!ena;
			butHuy.Enabled=!ena;
			butKetthuc.Enabled=!ena;
		}

		private void butMoi_Click(object sender, System.EventArgs e)
		{
			l_id=0;
			try
			{
				stt.Value=decimal.Parse(a.get_data("select max(stt) from a_dmng where loaikp=0").Tables[0].Rows[0][0].ToString())+1;
			}
			catch{stt.Value=1;}
			ma.Text=ten.Text=mact.Text=matieuct.Text=thuocct.Text=ngaybd.Text=ngaykt.Text="";
			tongkpdd.Text=kpnamnay.Text=sokptnlk.Text=coquanth.Text=mang.Text=mn_syt.Text="";
			hide.Checked=false;
			ena_object(true);
			stt.Focus();
		}

		private void butSua_Click(object sender, System.EventArgs e)
		{
			if (dt.Rows.Count==0) return;
			l_id=long.Parse(dataGrid1[dataGrid1.CurrentCell.RowNumber,0].ToString());
			ena_object(true);
			stt.Focus();
		}

		private bool kiemtra()
		{
			if (ma.Text=="")
			{
				MessageBox.Show("Mã số dự án !",a.Msg);
				ma.Focus();
				return false;
			}
			if (ten.Text=="")
			{
				MessageBox.Show("Tên dự án !",a.Msg);
				ten.Focus();
				return false;
			}
			if (thuocct.Text=="")
			{
				MessageBox.Show("Tên chương trình !",a.Msg);
				thuocct.Focus();
				return false;
			}
			decimal kp=(tongkpdd.Text!="")?Decimal.Parse(tongkpdd.Text):0;
			if (kp==0)
			{
				MessageBox.Show("Nhập tổng kinh phí ",a.Msg);
				tongkpdd.Focus();
				return false;
			}
			return true;
		}

		private void butLuu_Click(object sender, System.EventArgs e)
		{
			if (!kiemtra()) return ;
			bool bNew=l_id==0;
			l_id=(l_id==0)?a.getIddmng():l_id;
			if (!a.upd_dmng(l_id,stt.Value,mang.Text,ten.Text,"",0,thuocct.Text,ngaybd.Text,ngaykt.Text,coquanth.Text,(tongkpdd.Text!="")?decimal.Parse(tongkpdd.Text):0,(sokptnlk.Text!="")?decimal.Parse(sokptnlk.Text):0,0,(kpnamnay.Text!="")?decimal.Parse(kpnamnay.Text):0,(hide.Checked)?0:1,ma.Text,mn_syt.Text,mact.Text,matieuct.Text,i_userid))
			{
				MessageBox.Show("Không cập nhật thông tin "+this.Text.Trim()+" !",a.Msg);
				return;
			}
			load_grid();
			ref_text();
			ena_object(false);
			butMoi.Focus();
		}

		private void butBoqua_Click(object sender, System.EventArgs e)
		{
			ref_text();
			ena_object(false);
			butMoi.Focus();
		}

		private void butHuy_Click(object sender, System.EventArgs e)
		{
			/*
			try
			{
				if (a.get_data("select * from a_sd"+s_mmyy.Substring(2,2)+" where madt="+long.Parse(dataGrid1[dataGrid1.CurrentCell.RowNumber,0].ToString())).Tables[0].Rows.Count!=0)
				{
					MessageBox.Show("Tên "+ten.Text+" đang sử dụng không cho phép hủy !",a.Msg);
					return;
				}
			}
			catch{}*/
			if (MessageBox.Show("Đồng ý hủy thông tin này !",a.Msg,MessageBoxButtons.YesNo,MessageBoxIcon.Question)==DialogResult.Yes)
			{
				a.execute_data("delete from a_dmng where id="+long.Parse(dataGrid1[dataGrid1.CurrentCell.RowNumber,0].ToString()));
				load_grid();
			}
		}

		private void ref_text()
		{
			try
			{
				int i=dataGrid1.CurrentCell.RowNumber;
				l_id=long.Parse(dataGrid1[i,0].ToString());
				DataRow r=a.getrowbyid(dt,"id="+l_id);
				if (r!=null)
				{
					stt.Value=decimal.Parse(r["stt"].ToString());
					ma.Text=r["mada"].ToString();
					ten.Text=r["ten"].ToString();
					mact.Text=r["mact"].ToString();
					matieuct.Text=r["matieuct"].ToString();
					thuocct.Text=r["thuocct"].ToString();
					ngaybd.Text=r["bd"].ToString();
					ngaykt.Text=r["kt"].ToString();
					decimal st=decimal.Parse(r["tongkpdd"].ToString());
					tongkpdd.Text=st.ToString("###,###,###,###,###");
					st=decimal.Parse(r["kpnamnay"].ToString());
					kpnamnay.Text=st.ToString("###,###,###,###,###");
					st=decimal.Parse(r["sokptnlk"].ToString());
					sokptnlk.Text=st.ToString("###,###,###,###,###");
					coquanth.Text=r["coquanth"].ToString();
					mang.Text=r["mang"].ToString();
					mn_syt.Text=r["mn_syt"].ToString();
					hide.Checked=r["sudung"].ToString()=="0";
				}
			}
			catch{}
		}

		private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)
		{
			ref_text();
		}

		private void frmDmng_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode==Keys.F10) butKetthuc_Click(sender,e);
		}

		private void stt_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode==Keys.Enter) SendKeys.Send("{Tab}");		
		}

		private void ma_Validated(object sender, System.EventArgs e)
		{
			if (ma.Text!="" && l_id==0)
			{
				DataRow r1=a.getrowbyid(dt,"mada='"+ma.Text+"'");
				if (r1!=null)
				{
					MessageBox.Show("Mã số đã nhập !",a.Msg);
					ma.Focus();
					return;
				}
				if (ten.Text=="") ten.Text=ma.Text;
			}
		}

		private void ten_Validated(object sender, System.EventArgs e)
		{
			if (l_id==0 && ten.Text!="")
			{
				DataRow r1=a.getrowbyid(dt,"ten='"+ten.Text+"'");
				if (r1!=null)
				{
					MessageBox.Show("Tên đã nhập !",a.Msg);
					ten.Focus();
				}
			}
		}

		private void RefreshChildren(string text)
		{
			try
			{
				CurrencyManager cm= (CurrencyManager)BindingContext[dataGrid1.DataSource];
				DataView dv=(DataView)cm.List;
				sql="mada like '%"+text.Trim()+"%' or ten like '%"+text.Trim()+"%' or thuocct like '%"+text.Trim()+"%' or coquanth like '%"+text.Trim()+"%'";
				dv.RowFilter=sql;
				ref_text();
			}
			catch{}
		}

		private void tim_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==tim) RefreshChildren(tim.Text);
		}

		private void tim_Enter(object sender, System.EventArgs e)
		{
			tim.Text="";
		}

		private void butExcel_Click(object sender, System.EventArgs e)
		{
			DataSet _DataSet =new DataSet();
			_DataSet=a._rdanhmucduan(tim.Text);
			frmReport _frmReport =new frmReport(a,_DataSet,"11","KT_danhmucdua.rpt");
			_frmReport.ShowDialog();

//			a.check_process_Excel();
//			string tenfile=a.Export_Excel(dt,"dmng");
//			oxl=new Excel.Application();
//			owb=(Excel._Workbook)(oxl.Workbooks.Open(tenfile,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value));
//			osheet=(Excel._Worksheet)owb.ActiveSheet;
//			oxl.ActiveWindow.DisplayGridlines=true;
//			oxl.ActiveWindow.DisplayZeros=false;
//			osheet.PageSetup.Orientation=XlPageOrientation.xlLandscape;
//			osheet.PageSetup.PaperSize=XlPaperSize.xlPaperA4;
//			osheet.PageSetup.LeftMargin=20;
//			osheet.PageSetup.RightMargin=20;
//			osheet.PageSetup.TopMargin=30;
//			osheet.PageSetup.CenterFooter="Trang : &P/&N";
//			osheet.get_Range("A2","A2").Select();
//			oxl.ActiveWindow.FreezePanes = true;
//			oxl.Visible=true;
		}

		private void ngaybd_Validated(object sender, System.EventArgs e)
		{
			if (ngaybd.Text=="") return;
			ngaybd.Text=ngaybd.Text.Trim();
			if (!a.bNgay(ngaybd.Text))
			{
				MessageBox.Show("Ngày không hợp lệ !",a.Msg);
				ngaybd.Focus();
				return;
			}
			ngaybd.Text=a.Ktngaygio(ngaybd.Text,10);
		}
		private void ngaykt_Validated(object sender, System.EventArgs e)
		{
			if (ngaykt.Text=="") return;
			ngaykt.Text=ngaykt.Text.Trim();
			if (!a.bNgay(ngaykt.Text))
			{
				MessageBox.Show("Ngày không hợp lệ !",a.Msg);
				ngaykt.Focus();
				return;
			}
			ngaykt.Text=a.Ktngaygio(ngaykt.Text,10);
			if (ngaybd.Text!="" && ngaykt.Text!="")
			{
				if (!a.bNgay(ngaykt.Text,ngaybd.Text))
				{
					MessageBox.Show("Ngày kết thúc không được nhỏ hơn ngày bắt đầu !",a.Msg);
					ngaykt.Focus();
					return;
				}
			}
		}

		private void tongkpdd_Validated(object sender, System.EventArgs e)
		{
			try
			{
				decimal st=(tongkpdd.Text!="")?decimal.Parse(tongkpdd.Text):0;
				tongkpdd.Text=st.ToString("###,###,###,###,###");
			}
			catch{}
		}

		private void kpnamnay_Validated(object sender, System.EventArgs e)
		{
			try
			{
				decimal st=(kpnamnay.Text!="")?decimal.Parse(kpnamnay.Text):0;
				kpnamnay.Text=st.ToString("###,###,###,###,###");
			}
			catch{}		
		}

		private void sokptnlk_Validated(object sender, System.EventArgs e)
		{
			try
			{
				decimal st=(sokptnlk.Text!="")?decimal.Parse(sokptnlk.Text):0;
				sokptnlk.Text=st.ToString("###,###,###,###,###");
			}
			catch{}
		}
	}
}
